<template>
	<view class="">
		<j-cell-group>
			<template v-for="(item,index) in VoiceTip">
				<j-cell @tap="setconfig(item,index)" v-if="item.VoiceEnum != 550" :key="index" :title="item.VoiceText"
					:more="false">
					<view slot="tips" v-if="item.VoiceEnum === DetectMotionDetectList[0].EventHandler.VoiceType">
						<uni-icons custom-prefix="iconfont" type="icon-duihao" size="24" color="#FF0025"></uni-icons>
					</view>
				</j-cell>
			</template>
		</j-cell-group>
		<!-- <uni-popup ref="inputDialog" type="dialog" :is-mask-click="false">
			<view class="form">
				<view class="u-f-ajc title">更改密码</view>
				<view class="form-item">
					<uni-easyinput  v-model="VoiceText" placeholder="请输入报警提示语"></uni-easyinput>
				</view>
				<view class="u-f-r form-item">
					<view class="u-f-ajc cancel" @click="close">取消</view>
					<view class="u-f-ajc conf" @click="submit">上传提示音</view>
				</view>
			</view>
		</uni-popup> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				VoiceTip: [],
				DetectMotionDetectList: []
			}
		},
		onLoad(options) {
			this.token = options.token
			this.getconfig('Ability.VoiceTipType');
			this.getconfig('Detect.MotionDetect');
		},
		methods: {
			// getconfig() {
			// 	uni.showLoading();
			// 	let token = this.token;
			// 	let data = {
			// 		Name: 'VoiceTip'
			// 	};
			// 	getApp().globalData.api.getconfig(data, token, (result) => {
			// 		uni.hideLoading();
			// 		console.log(result)
			// 		this.VoiceTip = result['Ability.VoiceTipType'].VoiceTip
			// 	});
			// },
			// 获取配置
			getconfig(v) {
				uni.showLoading();
				let token = this.token;
				let data = {
					Name: v
				};
				getApp().globalData.api.getconfig(data, token, (result) => {
					uni.hideLoading()
					console.log(result);
					if (v == 'Detect.MotionDetect') {
						this.DetectMotionDetectList = result['Detect.MotionDetect']
					}
					if (v == 'Ability.VoiceTipType') {
						this.VoiceTip = result['Ability.VoiceTipType'].VoiceTip
					}
				});
			},
			// 自定义
			setconfigVoice(e) {
				console.log(e)
				uni.showLoading();
				let token = this.token;
				let data = {
					Name: 'Ability.VoiceTipType',
					VoiceTip: [{
						VoiceEnum: e.VoiceEnum,
						VoiceText: e.VoiceText
					}]
				};
				getApp().globalData.api.setconfig(data, token, (result) => {
					uni.hideLoading();
					console.log(result)
					var pages = getCurrentPages();
					var currPage = pages[pages.length - 1] //当前页面
					var prePage = pages[pages.length - 2] //上一个页面
					//调用上一页拉取数据的方法
					console.log(prePage)
					if (prePage.route == "jvss/pagesDevice/device/device-live/setting/IPolice/callThePolice") {
						prePage.$vm.this.getconfig('Detect.MotionDetect');
					}
					uni.navigateBack({
						delta: 1
					});
				});
			},
			// 选择设备警铃
			setconfig(e) {
				console.log(e)
				uni.showLoading();
				this.DetectMotionDetectList[0].EventHandler.VoiceType = e.VoiceEnum
				let token = this.token;
				let data = {
					Name: 'Detect.MotionDetect',
					'Detect.MotionDetect': this.DetectMotionDetectList
				};
				getApp().globalData.api.setconfig(data, token, (result) => {
					uni.hideLoading();
					uni.navigateBack({
						delta: 1
					});
					console.log(result)
					var pages = getCurrentPages();
					var prePage = pages[pages.length - 2] //上一个页面
					//调用上一页拉取数据的方法
					console.log(prePage)
					if (prePage.route == "jvss/pagesDevice/device/device-live/setting/IPolice/callThePolice") {
						prePage.$vm.getconfig('Detect.MotionDetect');
					}
				});
			},
		}
	}
</script>

<style>
</style>
